//
//  BaseViewController.swift
//  WeiBoDemo
//
//  Created by mac on 2017/11/18.
//  Copyright © 2017年 mac. All rights reserved.
//

import UIKit

class BaseViewController: UITableViewController {

    //MARK: 定义变量private
    lazy var visitorView : VisitorView = VisitorView.visitorView()
    
    var isLogin : Bool = true
    
    override func loadView() {
        isLogin ? super.loadView() : setupVisitorView()
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()

        setupNavigationItems()
    }

    
}

extension BaseViewController{
    private func setupVisitorView(){
        view = visitorView
        //监听访客视图中注册和登录按钮的点击
        visitorView.registerBtn.addTarget(self, action: #selector(BaseViewController.registerBtnClick), for: .touchUpInside)
        visitorView.loginBtn.addTarget(self, action: #selector(BaseViewController.loginBtnClick), for: .touchUpInside)
    }
    
    //设置导航栏左右的Item
    private func setupNavigationItems() {
        navigationItem.leftBarButtonItem = UIBarButtonItem.init(title: "注册", style: .plain, target: self, action: #selector(BaseViewController.registerBtnClick))
        navigationItem.rightBarButtonItem = UIBarButtonItem.init(title: "登录", style: .plain, target: self, action: #selector(BaseViewController.loginBtnClick))
    }
}

//MARK:- 事件监听
extension BaseViewController{
    @objc private func registerBtnClick() {
        print("注册")
    }
    @objc private func loginBtnClick() {
        print("登录")
    }
}
